package com.hsl.test;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
import org.jetbrains.annotations.NotNull;

public class MyToolWindowFactory implements ToolWindowFactory, Condition<Project> {

    /**
     * Create the tool window content.
     *
     * @param project    current project
     * @param toolWindow current tool window
     */
    public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
        //创建出Window对象
        MyToolWindow myToolWindow = new MyToolWindow(toolWindow);
        //获取内容工厂的实例
        ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
        //获取用于toolWindow显示的内容
        Content content = contentFactory.createContent(myToolWindow.getContent(), "自定义window", false);
        //给toolWindow设置内容
        toolWindow.getContentManager().addContent(content);
    }

    /**
     * 控制tool window是否展示
     * @param project
     * @return
     */
    @Override
    public boolean value(Project project) {
        return true;
    }

}
